<template>
  <div class="edu-page-warp">
    <div class="edu-page-title">
      个人计划成绩统计
    </div>
    <scoreStatistics
      v-if="rawLabels"
      :labels="rawLabels"
      :courses="rawCourses"
    />
    <div class="edu-page-title">
      个人培养计划
    </div>
    <graduatePlan
      v-if="studentCultureRel&&(trainingLevel==4||trainingLevel==6)"
      is-pass=1
      :show-title=false
      prev=true
      :student-culture-rel="studentCultureRel"
    />
  </div>
</template>
<script>
import { mapState } from "vuex";
import {
  findStudentCultureRelById,
  getCulturePlanByStudentId
} from "common/src/api/culture/culturePlan";
import scoreStatistics from "./scoreStatistics";
import graduatePlan from "./graduatePlan";
export default {
  name: "cultureScoreStatistics",
  components: {
    scoreStatistics,
    graduatePlan
  },
  computed: {
    ...mapState({
      mockUser: state => state.session.mockUser
    })
  },
  mounted: function() {
    let uid = this.mockUser ? this.mockUser.uid : localStorage.getItem("uid");

    getCulturePlanByStudentId(uid, 1)
      .then(res => {
        if (res.code == 200) {
          this.rawLabels = res.data.coursesLabelList;
          let fn = c => {
            return {
              id: c.id,
              courseCode: c.code,
              courseName: c.name,
              score: c.credits,
              studyTime: c.period,
              startTime: c.semester,
              startCollege: "",
              remark: c.remark,
              examScore: c.score,
              finished: c.isPass,
              pid: c.labelId
            };
          };
          if (res.data.culturePlanList) {
            this.rawCourses = res.data.culturePlanList.map(fn);
            return true;
          }else{
            return false;
          }
        }
      })
      .then((status) => {
        if(!status){
          return;
        }
        findStudentCultureRelById(uid).then(res => {
          if (res.code == 200) {
            this.studentCultureRel = res.data;
            this.trainingLevel = res.data.trainingLevelCode;
          }
        });
      });
  },
  data() {
    return {
      rawLabels: null,
      rawCourses: null,
      studentCultureRel: null,
      trainingLevel: null
    };
  },
  methods: {}
};
</script>
